//
// Created by 高森森 on 2022/10/6.
//

#ifndef LEETCODE_SOLUTION_12_H
#define LEETCODE_SOLUTION_12_H
#include<bits/stdc++.h>
using namespace std;

class solution_12 {
public:
    void moveZeroes(vector<int>& nums) {
        if(nums.size()==1){
            return;
        }
        int left=0,right=0;
        while(right<nums.size()){
            if(nums[left]==0){
                while(right<nums.size()&&nums[right]==0){
                    right++;
                }
                if(right<nums.size())
                swap(nums[left],nums[right]);
            }
            left++;
            right++;
        }
        for(int n:nums){
            cout<<n<<" ";
        }
    }
    void swap(int &a,int &b){
        int tmp=a;
        a=b;
        b=tmp;
    }
};


#endif //LEETCODE_SOLUTION_12_H
